cmake_minimum_required(VERSION 2.8)
# Project Name
PROJECT(Kinect_player_3)

#########################################################
# Find QT4 Libraries
#########################################################
FIND_PACKAGE(Qt4 REQUIRED)

#########################################################
# FIND OPENCV 2.3.1
#########################################################
#FIND_PACKAGE(OpenCV 2.3.1 REQUIRED)

#########################################################
# Find OpenNI
#
# This sets the following variables:
# OPENNI_FOUND - True if OPENNI was found.
# OPENNI_INCLUDE_DIRS - Directories containing the OPENNI include files.
# OPENNI_LIBRARIES - Libraries needed to use OPENNI.
# OPENNI_DEFINITIONS - Compiler flags for OPENNI.

find_package(PkgConfig)
if(${CMAKE_VERSION} VERSION_LESS 2.8.2)
  pkg_check_modules(PC_OPENNI openni-dev)
else()
  pkg_check_modules(PC_OPENNI QUIET openni-dev)
endif()

set(OPENNI_DEFINITIONS ${PC_OPENNI_CFLAGS_OTHER})

#add a hint so that it can find it without the pkg-config
find_path(OPENNI_INCLUDE_DIR XnStatus.h
          HINTS ${NESTK_ROOT_DIRS_HINTS} ${PC_OPENNI_INCLUDEDIR} ${PC_OPENNI_INCLUDE_DIRS} /usr/include/openni /usr/include/ni
          PATHS "$ENV{PROGRAMFILES}/OpenNI/Include" "$ENV{PROGRAMW6432}/OpenNI/Include"
          PATH_SUFFIXES openni)
#add a hint so that it can find it without the pkg-config
find_library(OPENNI_LIBRARY
             NAMES OpenNI64 OpenNI
             HINTS ${NESTK_ROOT_DIRS_HINTS} ${PC_OPENNI_LIBDIR} ${PC_OPENNI_LIBRARY_DIRS} /usr/lib
             PATHS "$ENV{PROGRAMFILES}/OpenNI/Lib${OPENNI_SUFFIX}" "$ENV{PROGRAMW6432}/OpenNI/Lib${OPENNI_SUFFIX}"
             PATH_SUFFIXES lib
)
find_library(NITE_LIBRARY
             NAMES XnVNite XnVNITE_1_3_1 XnVNITE_1_4_0 XnVNite_1_4_2 XnVNite_1_5_2
             HINTS ${NESTK_ROOT_DIRS_HINTS} ${PC_OPENNI_LIBDIR} ${PC_OPENNI_LIBRARY_DIRS} /usr/lib
             PATHS "$ENV{PROGRAMFILES}/PrimeSense/NITE/Lib${OPENNI_SUFFIX}" "$ENV{PROGRAMW6432}/PrimeSense/NITE/Lib${OPENNI_SUFFIX}"
             PATH_SUFFIXES lib
)

find_path(NITE_INCLUDE_DIR XnVSessionManager.h
          HINTS ${NESTK_ROOT_DIRS_HINTS} ${PC_OPENNI_INCLUDEDIR} ${PC_OPENNI_INCLUDE_DIRS} /usr/include/openni /usr/include/nite
          PATHS "$ENV{PROGRAMFILES}/PrimeSense/NITE/Include" "$ENV{PROGRAMW6432}/PrimeSense/NITE/Include"
          PATH_SUFFIXES openni)

set(OPENNI_INCLUDE_DIRS ${OPENNI_INCLUDE_DIR} ${NITE_INCLUDE_DIR})
if(APPLE)
  set(OPENNI_LIBRARIES ${OPENNI_LIBRARY} ${NITE_LIBRARY} usb)
else()
  set(OPENNI_LIBRARIES ${OPENNI_LIBRARY} ${NITE_LIBRARY})
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenNI DEFAULT_MSG
    OPENNI_LIBRARY OPENNI_INCLUDE_DIR)

mark_as_advanced(OPENNI_LIBRARY OPENNI_INCLUDE_DIR)
if(OPENNI_FOUND)
  include_directories(${OPENNI_INCLUDE_DIRS})
  link_directories(${OPENNI_LIBRARY})
  add_definitions(${OPENNI_DEFINITIONS})
  message(STATUS "OpenNI found (include: ${OPENNI_INCLUDE_DIR}, lib: ${OPENNI_LIBRARY})")
endif(OPENNI_FOUND)

#########################################################
# FIND GLUT
#########################################################
#find_package(GLUT REQUIRED)
#include_directories(${GLUT_INCLUDE_DIRS})
#link_directories(${GLUT_LIBRARY_DIRS})
#add_definitions(${GLUT_DEFINITIONS})
#########################################################
# FIND OPENGL
#########################################################
#find_package(OpenGL REQUIRED)
#include_directories(${OpenGL_INCLUDE_DIRS})
#link_directories(${OpenGL_LIBRARY_DIRS})
#add_definitions(${OpenGL_DEFINITIONS})

#########################################################
# FIND PCL
#########################################################
find_package(PCL REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})


#########################################################
# FIND PCL
#########################################################
find_package(VTK REQUIRED)
include_directories(${VTK_INCLUDE_DIRS})
link_directories(${VTK_LIBRARY_DIRS})
add_definitions(${VTK_DEFINITIONS})

#########################################################
# Pre compilation with QT4
#########################################################
SET(qtmatch_SOURCES main.cpp kinect_gui.cpp  )
SET(qtmatch_HEADERS kinect_gui.h )
SET(qtmatch_FORMS kinect_gui.ui)
#SET(helloworld_RESOURCES images.qrc)

SET(QT_USE_QTOPENGL TRUE)
#QT_USE_QTNETWORK
#QT_USE_QTOPENGL
#QT_USE_QTSQL
#QT_USE_QTXML
#QT_USE_QTSVG
#QT_USE_QTTEST
#QT_USE_QTDBUS
#QT_USE_QTSCRIPT
#QT_USE_QTWEBKIT
#QT_USE_QTXMLPATTERNS
#QT_USE_PHONON


QT4_WRAP_CPP(qtmatch_HEADERS_MOC ${qtmatch_HEADERS})
QT4_WRAP_UI(qtmatch_FORMS_HEADERS ${qtmatch_FORMS})
#QT4_ADD_RESOURCES(helloworld_RESOURCES_RCC ${helloworld_RESOURCES})



#########################################################
# Linking & stuff
#########################################################
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
#INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/GL)
SET(BUILD_TYPE Debug)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})

ADD_EXECUTABLE( gui
	${qtmatch_SOURCES} 
	${qtmatch_HEADERS_MOC} 
    	${qtmatch_FORMS_HEADERS} 
	${qtmatch_RESOURCES_RCC}
		)
TARGET_LINK_LIBRARIES(gui ${QT_LIBRARIES})
TARGET_LINK_LIBRARIES(gui ${OPENNI_LIBRARY})
#TARGET_LINK_LIBRARIES(gui ${GLUT_LIBRARY})
#TARGET_LINK_LIBRARIES(gui ${OpenCV_LIBS})
TARGET_LINK_LIBRARIES(gui ${PCL_LIBRARIES})
TARGET_LINK_LIBRARIES(gui ${VTK_LIBRARIES})
TARGET_LINK_LIBRARIES(gui QVTK vtkHybrid )
